﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FeedAntGame.Control;

namespace FeedAntGame.Sprite.Combo
{
    class BatterySprite : ComboBaseSprite
    {
        BatteryPower bot;
        BatteryPower top;
        BatteryPower body;
        Vector2 bottomPos;
        float power = 1.0f;
        /// <summary>
        /// 1.0f: 100%
        /// </summary>
        public float Power
        {
            get { return power; }
            set { power = value; }
        }

        public override float Scale
        {
            get { return scale; }
            set
            {
                scale = value;
                scaleWidth = value;
                scaleHeight = value;
                bot.Sprite.Scale = value;
                top.Sprite.Scale = value;
                body.Sprite.Scale = value;
            }
        }
        public BatterySprite(Texture2D background, Vector2 position, Point frameSize, int collisionOffset, Point sheetSize,
            Vector2 speed, string collisionCueName, float scale, Game game, BatteryPower bot, BatteryPower body,BatteryPower top)
            : base(background, position, frameSize, collisionOffset, sheetSize, speed, collisionCueName, scale, game)
        {
            this.bot = bot;
            this.top = top;
            this.body = body;
            this.bottomPos = this.bot.Sprite.Position + new Vector2(0, bot.Sprite.Height);
        }


        public override Vector2 Direction
        {
            get { return speed; }
        }

        public override void Update(GameTime gameTime, Rectangle clientBounds)
        {
            Position += Direction;
            bot.Sprite.Update(gameTime, clientBounds);
            body.Sprite.Update(gameTime, clientBounds);
            top.Sprite.Update(gameTime, clientBounds);

            //update position between top, bot, body
            top.Sprite.ScaleHeight = power * Scale;
            body.Sprite.ScaleHeight = power * Scale;
            bot.Sprite.ScaleHeight = power * Scale;

            bot.Sprite.Position = bottomPos - new Vector2(0, bot.Sprite.Height);
            body.Sprite.Position = bot.Sprite.Position - new Vector2(0, body.Sprite.Height-1);
            top.Sprite.Position = body.Sprite.Position - new Vector2(0, top.Sprite.Height-1);
            base.Update(gameTime, clientBounds);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);
            bot.Sprite.Draw(gameTime, spriteBatch);

            body.Sprite.Draw(gameTime, spriteBatch);
            top.Sprite.Draw(gameTime, spriteBatch);
        }
    }
}
